package org.matchergen;

import static org.hamcrest.Matchers.allOf;

import java.util.List;
import java.util.Vector;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class MatcherBuilder<T> extends TypeSafeMatcher<T> {
	List<Matcher<? super T>> matchers;

	public MatcherBuilder() {
		this.matchers = new Vector<Matcher<? super T>>();
	}

	protected void appendMatchers(Matcher<? super T> matcher) {
		this.matchers.add(matcher);
	}

	public void describeTo(Description description) {
		description.appendDescriptionOf(allOf(matchers));
	}

	@Override
	protected boolean matchesSafely(T item) {
		return allOf(matchers).matches(item);
	}
}
